package com.jzh.selfwallpaper.view.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.jzh.selfwallpaper.R;
import com.jzh.selfwallpaper.entity.ActiveListItem;
import com.jzh.selfwallpaper.view.activity.RaceLightActivity;
import com.jzh.selfwallpaper.view.adapter.ActiveFragmentAdapter;
import com.jzh.selfwallpaper.view.widget.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

public class Fragment_active extends BaseFragment {


    private ActiveFragmentAdapter activeFragmentAdapter;
    private RecyclerView rv_active_list;
    private List<ActiveListItem> list = new ArrayList<>();

    @Override
    protected int setView() {
        return R.layout.fragment_active;
    }

    @Override
    protected void init(View view) {

        rv_active_list = getActivity().findViewById(R.id.rv_active_list);
        activeFragmentAdapter = new ActiveFragmentAdapter(list, getActivity());
        //纵向线性布局
        //LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //SpaceItemDecoration spaceItemDecoration = new SpaceItemDecoration(20);
        //纵向线性布局
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 1);
        rv_active_list.setLayoutManager(new LinearLayoutManager(getActivity()));
        //rv_active_list.addItemDecoration(spaceItemDecoration);
        rv_active_list.setAdapter(activeFragmentAdapter);
        setListener();
    }

    private void setListener() {

        activeFragmentAdapter.setOnItemClickListener(new ActiveFragmentAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

                if (position == 0) {
                    startActivity(new Intent(getActivity(), RaceLightActivity.class));
                }
            }

            @Override
            public void onItemLongClick(View view) {

            }
        });
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        ActiveListItem activeListItem = new ActiveListItem();
        activeListItem.img_url = "https://www.newmobilelife.com/wp-content/uploads/2016/07/led5-1024x576.png";
        activeListItem.title = "手机迷妹跑马灯";
        list.add(activeListItem);
    }
}
